<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="renderer" content="webkit|ie-comp|ie-stand" />
		<meta name="wiewport" content="width=device-width, initial-scale=1.0, maxinum-scale=1.0, user-scaleable=no" />
		<title>账号列表-管理后台</title>
		<script type="text/javascript" src="/js/userCommon.js"></script>
	</head>

	<body class="main_body">
		<!--头部nav-->
		<div class="navbar navbar-default">
			<div class="container">
				<ul class="nav text-center quick_enter">
					<li><img src="/img/logo_login_03.jpg" class="nav_img" /></li>
					<li class="quick_enterli m-l-md">
						<a href="/entry.html">首页 </a>
					</li>
					<li class="quick_enterli">
						<a href="/theme.html" class="">强链接企业</a>
					</li>
					<li class="quick_enterli">
						<a href="/partner.html" class="">战略合作伙伴</a>
					</li>
					<li class="quick_enterli">
						<a href="/data.html" class="">数据看板</a>
					</li>
					<li class="dropdown pull-right admin_info">
						<img src="/img/shejishi_07.jpg" class="img-photo" />
						<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
							<span id="user_span"></span> <span class="drop_caret"></span>
						</a>
						<ul class="dropdown-menu">
							<li>
								<a href="/usercenter/myAttention.html" ><i class="fa fa-user-secret"></i> 个人中心</a>
							</li>
							<li class="hidden" id="backPageEnter1">
								<a href="#" ><i class="fa fa-server"></i> 后台管理</a>
							</li>
							<li>
								<a href="javascript:void(0)" id="logout_a"><i class="fa fa-sign-out"></i> 退出登录</a>
							</li>
						</ul>
					</li>
				</ul>
			</div>
		</div>
		<!--主体-->
		<div class="container containerbox">
			<!--左边导航-->
			<div class="left_side">
				<div class="ibox">
					<h3 class="topTitle">账号管理</h3>
					<ul class="leftMeun">
                        <li  class="active">
							<a href="/admin/accountList.html"><i class="fa fa-weixin" aria-hidden="true"></i>账号列表</a>
						</li>
						<li>
							<a href="/admin/addAccount.html"><i class="fa fa-unlink" aria-hidden="true"></i>新增账号</a>
						</li>
					</ul>
					<h3 class="topTitle">审核管理</h3>
					<ul class="leftMeun">
						<li>
							<a href="/admin/businessContactsExamine.html"><i class="fa fa-weixin" aria-hidden="true"></i>联系人审核</a>
                        </li>
                        <li>
							<a href="/admin/businessInteractionExamine.html"><i class="fa fa-weixin" aria-hidden="true"></i>链接互动审核</a>
                        </li>
                        <li>
							<a href="/admin/businessNeedExamine.html"><i class="fa fa-weixin" aria-hidden="true"></i>企业需求审核</a>
                        </li>
                        <li>
							<a href="/admin/businessList.html"><i class="fa fa-weixin" aria-hidden="true"></i>企业审核</a>
						</li>
						<li class="">
							<a href="/admin/partnerList.html"><i class="fa fa-weixin" aria-hidden="true"></i>合作伙伴审核</a>
						</li>
					</ul>
				</div>

			</div>
			<!--右边-->
			<div class="right_side">
				<div class="ibox">
					<div class="ibox-content" >
						<div class="comform-inline">
							<form class="form-inline">
								<div class="form-group">
									<label for="username">账号：</label>
									<input type="text" class="form-control" id="username" placeholder="请输入账号">
								</div>
								<div class="form-group">
									<label for="realname"> 姓&nbsp;&nbsp;&nbsp;&nbsp;名：</label>
									<input type="text" class="form-control" id="realname" placeholder="请输入姓名">
								</div>
								<!-- <div class="form-group">
									<label for="isRealName"> 用户类型：</label>
									<select class="form-control" id="isRealName" style="line-height: 1;">
										<option value="-1" selected>全部</option>
										<option value="0">游客</option>
										<option value="1">实名</option>
									</select>
								</div> -->
								<div style="height: 20px;"></div>
								<div class="form-group">
									<label for="unit">单位：</label>
									<input type="text" class="form-control" id="unit" placeholder="请输入单位">
								</div>
								<div class="form-group">
									<label for="mobile"> 手机号：</label>
									<input type="text" class="form-control" id="mobile" placeholder="请输入手机号">
								</div>
								<button type="button" class="btn btn-primary" onclick="loadData()">查询</button>
							</form>
						</div>
						<table class="table_at text-nowrap">
							<tbody>
								<tr class="ac_title">
									<th>用户ID</th>
									<th>用户类型</th>
									<th>用户名</th>
									<th>真实姓名</th>
									<th>联系电话</th>
									<th>职位</th>
									<th>单位</th>
									<th>状态</th>
									<th>操作</th>
								</tr>
							</tbody>
							<tbody id="list"></tbody>
						</table>
						<div class="pagination-box" style="display: block;">
							<ul class="pagination"></ul>
						</div>
					</div>
				</div>
			</div>
		</div>
		<!--footer-->
		<div class="footer" id="footerA"> </div>
		<div class="modal fade " tabindex="-1" role="dialog" id="myModal">
			<div class="modal-dialog modal-lg" role="document" >
				<div class="modal-content">
					<div class="modal-header">	
						<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
						<h4 class="modal-title"><i class="fa fa-pencil"></i> 新增账号</h4>
					</div>
					<div class="modal-body">
						<!--错误信息展示-->
						<div class="msg-wrap hidden">
							<div class="msg-error col-sm-8 col-sm-offset-3"><b></b><span id="msg_txt"></span></div>
						</div>
						<form action="" class="form-horizontal" id="form">
							<input type="hidden" id="id" />
							<div class="form-group">
								<label for="" class="col-sm-3 control-label"><span class="redStar">*</span> 账号:</label>
								<div class="col-sm-8 ">
									<input type="text" name="" class="form-control" id="username1" placeholder="请输入用户名">
								</div>
							</div>
							<div class="form-group">
								<label for="" class="col-sm-3 control-label"><span class="redStar">*</span> 密码:</label>
								<div class="col-sm-8 ">
									<input type="password" name="" class="form-control" id="password" placeholder="请输入新密码">
								</div>
							</div>
							<div class="form-group">
								<label for="" class="col-sm-3 control-label"><span class="redStar">*</span> 确认密码:</label>
								<div class="col-sm-8 ">
									<input type="password" name="" class="form-control" id="oldPassword" placeholder="请再次输入新密码">
								</div>
							</div>
							<div class="form-group">
								<label for="" class="col-sm-3 control-label"><span class="redStar">*</span> 是否管理员:</label>
								<div class="col-sm-4 ">
									<label class="radio-inline">
										<input type="radio" name="userType" id="userType0" value="0" checked> 是
									</label>
								</div>
								<div class="col-sm-4 ">
									<label class="radio-inline">
										<input type="radio" name="userType" id="userType1" value="1"> 否
									</label>
								</div>
							</div>
							<div class="form-group">
								<label for="" class="col-sm-3 control-label"> 用户角色:</label>
								<div class="col-sm-4 ">
									<label class="radio-inline">
										<input type="radio" name="userRole" id="userRole1" value="1"> 招商经理
									</label>
								</div>
								<div class="col-sm-4 ">
									<label class="radio-inline">
										<input type="radio" name="userRole" id="userRole2" value="2"> 研究经理
									</label>
								</div>
							</div>
							<div class="form-group">
								<label for="" class="col-sm-3 control-label"> 真实姓名:</label>
								<div class="col-sm-8 ">
									<input type="text" name="" class="form-control" id="realname" placeholder="请输入真实姓名">
								</div>
							</div>
							<div class="form-group">
								<label for="" class="col-sm-3 control-label"> 单位:</label>
								<div class="col-sm-8 ">
									<input type="text" name="" class="form-control" id="unit" placeholder="请输入单位">
								</div>
							</div>
							<div class="form-group">
								<label for="" class="col-sm-3 control-label"> 职位:</label>
								<div class="col-sm-8 ">
									<input type="text" name="" class="form-control" id="position" placeholder="请输入职位">
								</div>
							</div>
							<div class="form-group">
								<label for="" class="col-sm-3 control-label"> 手机号:</label>
								<div class="col-sm-8 ">
									<input type="text" name="" class="form-control" id="mobile" placeholder="请输入手机号">
								</div>
							</div>
							<div class="form-group">
								<label for="" class="col-sm-3 control-label"> 微信号:</label>
								<div class="col-sm-8 ">
									<input type="text" name="" class="form-control" id="wechat" placeholder="请输入微信号">
								</div>
							</div>
						</form>
					</div>
					<div class="modal-footer">
						<a href="javascript:void(0);" class="btn btn-primary btn-sm" onclick="save()">保存</a>
						<button type="button" class="btn btn-default btn-sm" data-dismiss="modal">关闭</button>
					</div>
				</div>
			</div>
		</div>
		<!--修改密码-->
		<div class="modal fade " tabindex="-1" role="dialog" id="myModal1">
			<div class="modal-dialog modal-lg" role="document" >
				<div class="modal-content">
					<div class="modal-header">	
						<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
						<h4 class="modal-title"><i class="fa fa-pencil"></i> 信息修改</h4>
					</div>
					<div class="modal-body">
						<!--错误信息展示-->
						<div class="msg-wrap hidden">
							<div class="msg-error col-sm-8 col-sm-offset-3"><b></b><span id="msg_txt"></span></div>
						</div>
						<form action="" class="form-horizontal" id="form">
							<input type="hidden" id="id" />
							<div class="form-group">
								<label for="" class="col-sm-3 control-label"><span class="redStar">*</span> 账号:</label>
								<div class="col-sm-8 ">
									<input type="text" name="" class="form-control" id="username2" placeholder="请输入用户名">
								</div>
							</div>
							<div class="form-group">
								<label for="" class="col-sm-3 control-label"><span class="redStar">*</span> 密码:</label>
								<div class="col-sm-8 ">
									<input type="password" name="" class="form-control" id="password2" placeholder="请输入新密码">
								</div>
							</div>
							<div class="form-group">
								<label for="" class="col-sm-3 control-label"><span class="redStar">*</span> 确认密码:</label>
								<div class="col-sm-8 ">
									<input type="password" name="" class="form-control" id="oldPassword2" placeholder="请再次输入新密码">
								</div>
							</div>
							<div class="form-group">
								<label for="" class="col-sm-3 control-label"><span class="redStar">*</span> 是否管理员:</label>
								<div class="col-sm-4 ">
									<label class="radio-inline">
										<input type="radio" name="userType" id="2userType0" value="0"> 是
									</label>
								</div>
								<div class="col-sm-4 ">
									<label class="radio-inline">
										<input type="radio" name="userType" id="2userType1" value="1"> 否
									</label>
								</div>
							</div>
							<div class="form-group">
								<label for="" class="col-sm-3 control-label"> 用户角色:</label>
								<div class="col-sm-4 ">
									<label class="radio-inline">
										<input type="radio" name="userRole" id="2userRole1" value="1"> 招商经理
									</label>
								</div>
								<div class="col-sm-4 ">
									<label class="radio-inline">
										<input type="radio" name="userRole" id="2userRole2" value="2"> 研究经理
									</label>
								</div>
							</div>
							<div class="form-group">
								<label for="" class="col-sm-3 control-label"> 真实姓名:</label>
								<div class="col-sm-8 ">
									<input type="text" name="" class="form-control" id="realname2" placeholder="请输入真实姓名">
								</div>
							</div>
							<div class="form-group">
								<label for="" class="col-sm-3 control-label"> 单位:</label>
								<div class="col-sm-8 ">
									<input type="text" name="" class="form-control" id="unit2" placeholder="请输入单位">
								</div>
							</div>
							<div class="form-group">
								<label for="" class="col-sm-3 control-label"> 职位:</label>
								<div class="col-sm-8 ">
									<input type="text" name="" class="form-control" id="position2" placeholder="请输入职位">
								</div>
							</div>
							<div class="form-group">
								<label for="" class="col-sm-3 control-label"> 手机号:</label>
								<div class="col-sm-8 ">
									<input type="text" name="" class="form-control" id="mobile2" placeholder="请输入手机号">
								</div>
							</div>
							<div class="form-group">
								<label for="" class="col-sm-3 control-label"> 微信号:</label>
								<div class="col-sm-8 ">
									<input type="text" name="" class="form-control" id="wechat2" placeholder="请输入微信号">
								</div>
							</div>
						</form>
					</div>
					<div class="modal-footer">
						<a href="javascript:void(0);" class="btn btn-primary btn-sm" onclick="editSave()">保存</a>
						<button type="button" class="btn btn-default btn-sm" data-dismiss="modal">关闭</button>
					</div>
				</div>
			</div>
		</div>
		<script type="text/javascript">
			var pageNo = 1
            var pageSize = 20
			var nowId = -1
			$(document).ready(function(){
				if($.cookie('AuthorizationAdmin')===null || localStorage.getItem('adminName') === null) {
					showErr("您处于未登录状态，请先登录", '1000000');
					return
				}

				$('#user_span').text(localStorage.getItem('realname') )

				$("#addAccount").click(function() {
					$('#myModal').modal('show');
				})

				loadData();
			})

			// 查询账号列表
			function loadData() {
				// var isRealName = $("#isRealName").val();
				var realname = $("#realname").val();
				var mobile = $("#mobile").val();
				var unit = $("#unit").val();
				var username = $("#username").val();

				var paramStr = ''
				// if (isRealName !== -1) {
				// 	paramStr = paramStr + 'isRealName=' + isRealName + '&'
				// }
				if (realname !== null) {
					paramStr = paramStr + 'realname=' + realname + '&'
				}
				if (mobile !== null) {
					paramStr = paramStr + 'mobile=' + mobile + '&'
				}
				if (unit !== null) {
					paramStr = paramStr + 'unit=' + unit + '&'
				}
				if (username !== null) {
					paramStr = paramStr + 'username=' + username + '&'
				}
				paramStr = paramStr + 'pageNo=' + pageNo + '&pageSize=' + pageSize + '&token=' + $.cookie('AuthorizationAdmin')
				$.ajax({
					url: service_url + '/a/zkUser/list?' + paramStr,
					type: 'GET',
                    xhrFields: {
                        withCredentials: true
                    },
                    crossDomain: true,
                    contentType: 'application/json',
                    dataType: 'jsonp',
                    jsonpCallback:"success_jsonpCallback",  
                    processData: false, // 告诉jQuery不要去处理发送的数据
					success: function(data) {
						$("#list").html("");
						var resData = JSON.parse(data.data);
						for (var i = 0; i < resData.list.length; i ++) {
							var status;
							if (resData.list[i].status == 0) {
								status = "禁用";
							}
							else if (resData.list[i].status == 1) {
								status = "正常";
							}
							else {
								status = "待审核";
							}

							var typeStr = ''
							if (resData.list[i].userType === 1) {
								typeStr = '非管理员'
							} else if (resData.list[i].userType === 0){
								typeStr = '管理员'
							}
							
							$("#list").append("<tr><td>" + resData.list[i].id + "</td>" + 
												"<td>" + typeStr + "</td>" + 
												"<td>" + resData.list[i].username + "</td>" + 
												"<td>" + (resData.list[i].realname || '') + "</td>" + 
												"<td>" + (resData.list[i].mobile || '') + "</td>" + 
												"<td>" + (resData.list[i].position || '') + "</td>" + 
												"<td>" + (resData.list[i].unit || '') + "</td>" + 
												"<td>" + status + "</td>" + 
												"<td><span class='do-add' onclick='enable(" + resData.list[i].id + ")'>启用</span><span class='do-delete' onclick='disable(" + resData.list[i].id + ")'>禁用</span><span class='do-edit' onclick='edit(" + resData.list[i].id + ")'>修改</span></tr>");
						}

							$('.pagination-box').show()
                            $('.pagination').jqPaginator({
                                totalCounts: resData.count,
                                pageSize: pageSize,
                                visiblePages: 10,
                                currentPage: pageNo,
                                first: '<li class="first"><a href="javascript:void(0);">首页<\/a><\/li>',
                                prev: '<li class="prev"><a href="javascript:void(0);">&laquo;<\/a><\/li>',
                                next: '<li class="next"><a href="javascript:void(0);">&raquo;<\/a><\/li>',
                                last: '<li class="last"><a href="javascript:void(0);">末页<\/a><\/li>',
                                page: '<li class="page"><a href="javascript:void(0);">{{page}}<\/a><\/li>',
                                onPageChange: function (num, type) {
                                    if (type === 'change') {
                                        pageNo = num
                                        loadData()
                                    }
                                }
                            });
					},
					error: function(XMLHttpRequest, textStatus, errorThrown) {}
				})
			}

			// 保存
			function save() {
				var username = $("#username1").val();
				var password = $("#password").val();
				var oldPassword = $("#oldPassword").val();
				var userType = 1;
				if ($('#userType0').is(':checked')) {
					userType = $('#userType0').val()
				}
				if ($('#userType1').is(':checked')) {
					userType = $('#userType1').val()
				}
				var userRole = 1;
				if ($('#userRole1').is(':checked')) {
					userRole = $('#userRole1').val()
				}
				if ($('#userRole2').is(':checked')) {
					userRole = $('#userRole2').val()
				}
				var realname = $("#realname").val();
				var unit = $("#unit").val();
				var position = $("#position").val();
				var mobile = $("#mobile").val();
				var wechat = $("#wechat").val();

				if (username == "") {
					alert("请输入账号！");
					return;
				}

				if (password == "") {
					alert("请输入密码！");
					return;
				}

				if (oldPassword == "") {
					alert("请再次输入密码！");
					return;
				}

				if (password != oldPassword) {
					alert("两次密码不一致！");
					return;
				}

				if (userType == "") {
					alert("请选择用户类型！");
					return;
				}
				
				$.ajax({
					url: service_url + '/a/zkUser/save',
					type: 'GET',
					data: { 
						username: username,
						password: password,
						oldPassword: oldPassword,
						userType: userType,
						userRole: userRole,
						realname: realname,
						unit: unit,
						position: position,
						mobile: mobile,
						wechat: wechat
     				},
					// xhrFields: {
					// 	withCredentials: true
					// },
					//crossDomain: true,
					contentType: 'application/json',
					dataType: 'jsonp',
					jsonpCallback:"success_jsonpCallback",  
					//processData: false, // 告诉jQuery不要去处理发送的数据
					beforeSend: function(request) {
						request.setRequestHeader("Authorization", $.cookie().Authorization);
					},
					success: function(data) {
						alert(data.msg);
						loadData();
						$('#myModal').modal('hide');
					},
					error: function(XMLHttpRequest, textStatus, errorThrown) {}
				})
			}



			// 修改
			function edit(id) {
				nowId = id
				$.ajax({
					url: service_url + '/a/zkUser/form',
					type: 'GET',
					data: { 
						id: id
     				},
					//xhrFields: {
						//withCredentials: true
					//},
					//crossDomain: true,
					contentType: 'application/json',
					dataType: 'jsonp',
					jsonpCallback:"success_jsonpCallback",  
					beforeSend: function(request) {
						request.setRequestHeader("Authorization", $.cookie().Authorization);
					},
					success: function(data) {
						var resData = JSON.parse(data.data);
						console.log(resData);
						$("#id").val(resData.id);
						$("#username2").val(resData.username);
						// $("#password").val(resData.password);

						if (resData.userType == "0") {
							$("#2userType0").attr("checked", true);
						}
						else {
							$("#2userType1").attr("checked", true);
						}
						
						if (resData.userRole == "1") {
							$("#2userRole1").attr("checked", true);
						}
						else {
							$("#2userRole2").attr("checked", true);
						}

						$("#realname2").val(resData.realname);
						$("#unit2").val(resData.unit);
						$("#position2").val(resData.position);
						$("#mobile2").val(resData.mobile);
						$("#wechat2").val(resData.wechat);
						$('#myModal1').modal('show');
					},
					error: function(XMLHttpRequest, textStatus, errorThrown) {}
				})
			}

			// 修改保存
			function editSave() {
				var username = $("#username2").val();
				var password = $("#password2").val();
				var oldPassword = $("#oldPassword2").val();
				var userType = 1;
				if ($('#2userType0').is(':checked')) {
					userType = $('#2userType0').val()
				}
				if ($('#2userType1').is(':checked')) {
					userType = $('#2userType1').val()
				}
				var userRole = 1;
				if ($('#2userRole1').is(':checked')) {
					userRole = $('#2userRole1').val()
				}
				if ($('#2userRole2').is(':checked')) {
					userRole = $('#2userRole2').val()
				}
				var realname = $("#realname2").val();
				var unit = $("#unit2").val();
				var position = $("#position2").val();
				var mobile = $("#mobile2").val();
				var wechat = $("#wechat2").val();
				if (username == "") {
					alert("请输入账号！");
					return;
				}

				if (password == "") {
					alert("请输入密码！");
					return;
				}

				if (oldPassword == "") {
					alert("请再次输入密码！");
					return;
				}

				if (password != oldPassword) {
					alert("两次密码不一致！");
					return;
				}

				if (userType == "") {
					alert("请选择用户类型！");
					return;
				}
				
				$.ajax({
					url: service_url + '/a/zkUser/save',
					type: 'GET',
					data: { 
						username: username,
						password: password,
						oldPassword: oldPassword,
						userType: userType,
						userRole: userRole,
						realname: realname,
						unit: unit,
						position: position,
						mobile: mobile,
						wechat: wechat,
						id: nowId
     				},
					// xhrFields: {
					// 	withCredentials: true
					// },
					//crossDomain: true,
					contentType: 'application/json',
					dataType: 'jsonp',
					jsonpCallback:"success_jsonpCallback",  
					//processData: false, // 告诉jQuery不要去处理发送的数据
					beforeSend: function(request) {
						request.setRequestHeader("Authorization", $.cookie().Authorization);
					},
					success: function(data) {
						alert(data.msg);
						loadData();
						$('#myModal1').modal('hide');
					},
					error: function(XMLHttpRequest, textStatus, errorThrown) {}
				})
			}

			// 启用
			function enable(id) {
				$.ajax({
					url: service_url + '/a/zkUser/verifyInfo',
					type: 'GET',
					data: { 
						id: id
     				},
					//xhrFields: {
						//withCredentials: true
					//},
					//crossDomain: true,
					contentType: 'application/json',
					dataType: 'jsonp',
					jsonpCallback:"success_jsonpCallback",  
					//processData: false, // 告诉jQuery不要去处理发送的数据
					beforeSend: function(request) {
						request.setRequestHeader("Authorization", $.cookie().Authorization);
					},
					success: function(data) {
						alert(data.msg);
						
						// $('.do-delete').click(function(){
						// 	top.confirm("您确定要删除账号吗", "", function(isConfirm) {
						// 		if(isConfirm) {
						// 			top.alert('删除账号成功!','','',{type: 'success'})
						// 		} else {
						// 			//after click the cancel
						// 		}
						// 	}, {
						// 		confirmButtonText: '确定',
						// 		cancelButtonText: '取消',
						// 		width: 400
						// 	});
						// })
					},
					error: function(XMLHttpRequest, textStatus, errorThrown) {}
				})
			}

			// 启用
			function disable(id) {
				$.ajax({
					url: service_url + '/a/zkUser/delete',
					type: 'GET',
					data: { 
						id: id
     				},
					//xhrFields: {
						//withCredentials: true
					//},
					//crossDomain: true,
					contentType: 'application/json',
					dataType: 'jsonp',
					jsonpCallback:"success_jsonpCallback",  
					//processData: false, // 告诉jQuery不要去处理发送的数据
					beforeSend: function(request) {
						request.setRequestHeader("Authorization", $.cookie().Authorization);
					},
					success: function(data) {
						if (data.status == "00") {
							$("#do-disable").off("click");
							//$("#do-disable").attr("onclick", "null");
							//$("#do-enable").attr("onclick", "enable()");
							alert('禁用成功');
						} else {
							alert(data.msg);
						}
						loadData();
					},
					error: function(XMLHttpRequest, textStatus, errorThrown) {}
				})
			}
		</script>
	</body>
</html>